package c.e.a.c.p;

import android.os.Build.VERSION;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.StaticLayout.Builder;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import java.lang.reflect.Constructor;
import java.util.Objects;

/* compiled from: StaticLayoutBuilderCompat */
public final class f {
    public static boolean j;
    public static Constructor<StaticLayout> k;
    public static Object l;
    public CharSequence a;
    public final TextPaint b;
    public final int c;
    public int d;
    public Alignment e = Alignment.ALIGN_NORMAL;
    public int f = Integer.MAX_VALUE;
    public boolean g = true;
    public boolean h;
    public TruncateAt i = null;

    /* compiled from: StaticLayoutBuilderCompat */
    public static class a extends Exception {
        public a(Throwable th) {
            StringBuilder g = c.b.a.a.a.g("Error thrown initializing StaticLayout ");
            g.append(th.getMessage());
            super(g.toString(), th);
        }
    }

    public f(CharSequence charSequence, TextPaint textPaint, int i) {
        this.a = charSequence;
        this.b = textPaint;
        this.c = i;
        this.d = charSequence.length();
    }

    public StaticLayout a() throws a {
        if (this.a == null) {
            this.a = "";
        }
        int max = Math.max(0, this.c);
        CharSequence charSequence = this.a;
        if (this.f == 1) {
            charSequence = TextUtils.ellipsize(charSequence, this.b, (float) max, this.i);
        }
        int min = Math.min(charSequence.length(), this.d);
        this.d = min;
        int i = VERSION.SDK_INT;
        if (i >= 23) {
            if (this.h) {
                this.e = Alignment.ALIGN_OPPOSITE;
            }
            Builder obtain = Builder.obtain(charSequence, 0, min, this.b, max);
            obtain.setAlignment(this.e);
            obtain.setIncludePad(this.g);
            obtain.setTextDirection(this.h ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);
            TruncateAt truncateAt = this.i;
            if (truncateAt != null) {
                obtain.setEllipsize(truncateAt);
            }
            obtain.setMaxLines(this.f);
            return obtain.build();
        }
        Constructor declaredConstructor;
        if (!j) {
            try {
                Object obj = (!this.h || i < 23) ? null : 1;
                Class cls = TextDirectionHeuristic.class;
                l = obj != null ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR;
                r4 = new Class[13];
                Class cls2 = Integer.TYPE;
                r4[1] = cls2;
                r4[2] = cls2;
                r4[3] = TextPaint.class;
                r4[4] = cls2;
                r4[5] = Alignment.class;
                r4[6] = cls;
                cls = Float.TYPE;
                r4[7] = cls;
                r4[8] = cls;
                r4[9] = Boolean.TYPE;
                r4[10] = TruncateAt.class;
                r4[11] = cls2;
                r4[12] = cls2;
                declaredConstructor = StaticLayout.class.getDeclaredConstructor(r4);
                k = declaredConstructor;
                declaredConstructor.setAccessible(true);
                j = true;
            } catch (Exception e) {
                throw new a(e);
            }
        }
        try {
            declaredConstructor = k;
            Objects.requireNonNull(declaredConstructor);
            r6 = new Object[13];
            Object obj2 = l;
            Objects.requireNonNull(obj2);
            r6[6] = obj2;
            r6[7] = Float.valueOf(1.0f);
            r6[8] = Float.valueOf(0.0f);
            r6[9] = Boolean.valueOf(this.g);
            r6[10] = null;
            r6[11] = Integer.valueOf(max);
            r6[12] = Integer.valueOf(this.f);
            return (StaticLayout) declaredConstructor.newInstance(r6);
        } catch (Exception e2) {
            throw new a(e2);
        }
    }
}
